package com.ruibang.glass.sale.controller;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.ruibang.glass.sale.domain.req.GSaleReturnIventoryReq;
import com.ruibang.glass.sale.entity.GSaleOrderManagement;
import com.ruibang.glass.sale.entity.GSaleReturnExchangeOrder;
import com.ruibang.glass.sale.entity.GSaleReturnInventory;
import com.ruibang.glass.sale.entity.SaleReturnInventoryProduct;
import com.ruibang.glass.sale.service.GSaleReturnExchangeOrderService;
import com.ruibang.glass.sale.service.GSaleReturnInventoryService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author mameng
 */
@Api(tags = "退换货入库单")
@RestController
@RequestMapping("/api/glass/sale/return/inventory")
public class GSaleReturnIventoryController {
    @Autowired
    private GSaleReturnExchangeOrderService gSaleReturnExchangeOrderService;

    @Autowired
    private GSaleReturnInventoryService gSaleReturnInventoryService;

    @PostMapping("list")
    @ApiOperation(value = "退换货入库单列表", response = ResultBody.class)
    public ResultBody list(@RequestBody GSaleReturnIventoryReq gSaleReturnIventoryReq) {
        return ResultBody.success(gSaleReturnInventoryService.getPage(gSaleReturnIventoryReq));
    }

    @GetMapping("getReNumber")
    @ApiOperation(value = "退货单号", response = ResultBody.class)
    public ResultBody getReNumber() {
        return ResultBody.success(gSaleReturnInventoryService.generateNextSerialNumber());
    }

    @GetMapping("getINNumber")
    @ApiOperation(value = "入库单号", response = ResultBody.class)
    public ResultBody getINNumber() {
        return ResultBody.success(gSaleReturnInventoryService.getINNumber());
    }


    @PostMapping("updateGSaleReturnInventory")
    @ApiOperation(value = "入库申请", response = ResultBody.class)
    public ResultBody list(@RequestBody GSaleReturnInventory saleReturnInventory) {
        gSaleReturnInventoryService.updateGSaleReturnInventory(saleReturnInventory);
        return ResultBody.success();
    }

    @GetMapping("getOne/{id}")
    @ApiOperation(value = "详情", response = ResultBody.class)
    public ResultBody list(@PathVariable("id") String id) {
        return ResultBody.success(gSaleReturnInventoryService.getGSaleReturnInventory(id));
    }

    @PostMapping("updateGSaleReturnInventoryReQuality")
    @ApiOperation(value = "入库申请", response = ResultBody.class)
    public ResultBody updateGSaleReturnInventoryReQuality(@RequestBody List<SaleReturnInventoryProduct> saleReturnInventory) {
        gSaleReturnInventoryService.updateGSaleReturnInventoryReQuality(saleReturnInventory);
        return ResultBody.success();
    }
}
